﻿using System;
using Repo.Interfaces;

namespace Repo.FieldTypes
{
    public class LookupSingleChoice : IComplexFieldType
    {
        public int Id { get; set; }

        public string Value { get; set; }

        public IComplexFieldType SetInstanceValue(object value)
        {
            if (value != null)
            {
                var split = value.ToString().Split(";#".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                return split.Length == 1
                           ? new LookupSingleChoice {Id = int.Parse(split[0]), Value = string.Empty}
                           : new LookupSingleChoice {Id = int.Parse(split[0]), Value = split[1]};
            }
            return null;
        }
    }
}
